package bsh.meta;

import org.objectweb.asm.MethodVisitor;

import bsh.CompilationState;
import bsh.exception.CompilationFailedException;

/**
 * Classe responsavel por conversao de tipos
 * 
 * @author takeshi
 */
public interface TypeTransformation {

    /**
     * Verifica se este {@link TypeTransformation} pode ser aplicado ao {@link TypeWrapper} passado
     * 
     * @param type {@link TypeWrapper}
     * @return boolean
     */
    boolean acceptsType(TypeWrapper type);

    /**
     * Devolve o tipo que sera o resultante da aplicacao deste {@link TypeTransformation} no {@link TypeWrapper} passado
     * 
     * @param fromType {@link TypeWrapper}
     * @return {@link TypeWrapper}
     */
    TypeWrapper toType(TypeWrapper fromType);

    /**
     * Gera as instrucoes para converter o tipo que esta no topo do stack
     * 
     * @param visitor {@link MethodVisitor}
     * @param fromType {@link TypeWrapper}
     * @param state {@link CompilationState}
     * @return {@link TypeWrapper} o tipo resultante
     * @throws CompilationFailedException e
     */
    TypeWrapper transformStackTop(MethodVisitor visitor, TypeWrapper fromType, CompilationState state) throws CompilationFailedException;

}
